{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from bqplot import (DateScale, LinearScale, ColorScale, \n",
    "                    Axis, ColorAxis, Figure, FlexLine)\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\n",
    "size = len(dates)\n",
    "spx = 100 + 5 * np.cumsum(np.random.randn(size))\n",
    "vix = 10 + np.cumsum(np.random.randn(size))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Displaying extra dimension with color"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "lin_x = DateScale()\n",
    "lin_y = LinearScale()\n",
    "col_line = ColorScale(colors=['green', 'white', 'red'])\n",
    "\n",
    "ax_x = Axis(scale=lin_x, label='Date', label_location='end')\n",
    "ax_y = Axis(scale=lin_y, orientation='vertical', label='Index', label_offset='4ex')\n",
    "ax_col = ColorAxis(label='Vol', scale=col_line, tick_format='0.2f')\n",
    "\n",
    "fig_margin = dict(top=50, left=80, right=20, bottom=70)\n",
    "fl = FlexLine(x=dates, y=spx, color=vix,\n",
    "              scales={'x': lin_x, 'color': col_line, 'y': lin_y})\n",
    "\n",
    "Figure(marks=[fl], axes=[ax_x, ax_y, ax_col], fig_margin=fig_margin)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Displaying extra dimension with width"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "lin_x = DateScale()\n",
    "lin_y = LinearScale()\n",
    "width_line = LinearScale()\n",
    "\n",
    "\n",
    "ax_x = Axis(scale=lin_x, label='Date')\n",
    "ax_y = Axis(scale=lin_y, orientation='vertical', label='SPX Index')\n",
    "\n",
    "fl2 = FlexLine(x=dates, y=spx, width=vix,\n",
    "               scales={'x': lin_x, 'width': width_line, 'y': lin_y},\n",
    "               stroke_width=5)\n",
    "\n",
    "Figure(marks=[fl2], axes=[ax_x, ax_y])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
